package com.ruoyi.project.system.depart.controller;

import java.util.List;

import com.ruoyi.project.system.depart.domain.Depart;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.depart.service.IDepartService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * exampleController
 * 
 * @author ruoyi
 * @date 2021-09-27
 */
@Api("depart操作")
@Controller
@RequestMapping("/demo/depart")
public class DepartController extends BaseController
{
    private String prefix = "demo/depart";

    @Autowired
    private IDepartService departService;

    @GetMapping()
    public String depart()
    {
        return prefix + "/depart";
    }

    /**
     * 查询example列表
     */
    @ApiOperation("查询参数列表")
    @PostMapping("/list")
    @Log(title = "depart管理", businessType = BusinessType.INSERT)
    @ResponseBody
    public TableDataInfo list(Depart depart)
    {
        startPage();
        List<Depart> list = departService.selectDepartList(depart);
        return getDataTable(list);
    }

    /**
     * 导出example列表
     */
    @ApiOperation("导出参数列表")
    @Log(title = "example", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Depart depart)
    {
        List<Depart> list = departService.selectDepartList(depart);
        ExcelUtil<Depart> util = new ExcelUtil<Depart>(Depart.class);
        return util.exportExcel(list, "example数据");
    }

    /**
     * 新增example
     */
    @ApiOperation("添加参数列表")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存example
     */
    @Log(title = "example", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Depart depart)
    {
        return toAjax(departService.insertDepart(depart));
    }

    /**
     * 修改example
     */
    @ApiOperation("修改参数列表")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Depart depart = departService.selectDepartById(id);
        mmap.put("depart", depart);
        return prefix + "/edit";
    }

    /**
     * 修改保存example
     */
    @Log(title = "example", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Depart depart)
    {
        return toAjax(departService.updateDepart(depart));
    }

    /**
     * 删除example
     */
    @ApiOperation("删除参数列表")
    @Log(title = "example", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(departService.deleteDepartByIds(ids));
    }
}
